<?php

/**
 * 分类广告后台管理
 * @copyright (c) 2013, Alvin
 * 
 */
class CatadAction extends AdminAction {

    public function _initialize() {
        parent::_initialize();
    }

    public function check() {
        $id        = (int) $this->_get("id");
        $id        = (int) $this->_get("id");
        $model     = M('Catad');
        $page      = M('PayPage');
        $linkmodel = D('PayLink');

        $param                 = $model->find($id);
        $param['star_time']    = time();
        $param['end_time']     = time() + 24 * 3600 * (int) $param['days'];
        $param['status_check'] = 'true';
        if ($param['article_id']) {
            $payPage              = $page->find($param['article_id']);
            $payPage['star_time'] = time();
            $payPage['end_time']  = time() + 24 * 3600 * $param['article_days'];
            $page->save($payPage);
        }

        if ($param['link_id']) {
            $link              = $linkmodel->find($param['link_id']);
            $link['star_time'] = time();
            $link['end_time']  = time() + 24 * 3600 * $param['link_days'];
            $linkmodel->save($link);
        }
        $res               = $model->save($param);
        $decScore          = D('UserAccount')->chargeUserAccount($param['user_id'], -$param['pay_score'], 'FABU_CATAD', '发布分类广告扣除金币' . $param['pay_score']);
        if ($decScore['status'] == false) {
            $this->error("操作失败:" . $decScore['msg']);
        }
        if ($res) {
            $this->success("操作成功！");
        } else {
            $this->error("操作失败！");
        }
    }

    public function delete() {
        $id = (int) $this->_get("id");
        if (M('Catad')->delete($id)) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }

}

?>
